<!DOCTYPE html>
<html lang='en'>

<head>
  <meta charset='UTF-8'>
  <meta http-equiv='X-UA-Compatible' content='IE=edge'>
  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
  <title>存档</title>
  <script src="../js/jszip.min.js"></script>
  <script src="../js/epub.js"></script>
  <link rel="stylesheet" href="css.css">
</head>

<body>
  <div id="viewer" class="spreads"></div>
  <div id="prev" class="arrow">‹</div>
  <div id="next" class="arrow">›</div>
  <script>
    var book = ePub("../epub/自控力.epub");
    var rendition = book.renderTo("viewer", {
      width: "100%",
      height: 600
    });

    var displayed = rendition.display();

    // 这是 themes 对象就是处理样式的。 http://epubjs.org/documentation/0.3/#themes
    var themes = rendition.themes;


    displayed.then(function (renderer) {
      console.log(`renderer`, renderer)
      // -- do stuff
    });

    // Navigation loaded
    book.loaded.navigation.then(function (toc) {
      console.log(toc);
    });

    var next = document.getElementById("next");
    next.addEventListener("click", function () {
      rendition.next();
    }, false);

    var prev = document.getElementById("prev");
    prev.addEventListener("click", function () {
      rendition.prev();
    }, false);

    var keyListener = function (e) {

      // Left Key
      if ((e.keyCode || e.which) == 37) {
        rendition.prev();
      }

      // Right Key
      if ((e.keyCode || e.which) == 39) {
        rendition.next();
      }

    };

    rendition.on("keyup", keyListener);
    document.addEventListener("keyup", keyListener, false);


  </script>

</body>

</html>